package com.fr.chart;

import com.fr.base.XMLable;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.SeriesAttrAlpha;
import com.fr.chart.axis.SeriesAttrBorder;
import com.fr.chart.axis.SeriesAttrColor;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.plot.SeriesCollection;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;

public class ColorInfo
  implements XMLable, GlyphCondition
{
  private static final long serialVersionUID = -2219673427793792660L;
  public static final String XML_TAG = "ColorInfo";
  private SeriesAttrAlpha seriesAttrAlpha = new SeriesAttrAlpha();
  private SeriesAttrBorder seriesAttrBorder = new SeriesAttrBorder();
  private SeriesAttrColor seriesAttrColor = new SeriesAttrColor();

  public void setSeriesColor(Color paramColor)
  {
    getSeriesAttrColor().setSeriesColor(paramColor);
  }

  public Color getSeriesColor()
  {
    return getSeriesAttrColor().getSeriesColor();
  }

  public void setSeriesAttrColor(SeriesAttrColor paramSeriesAttrColor)
  {
    this.seriesAttrColor = paramSeriesAttrColor;
  }

  public SeriesAttrColor getSeriesAttrColor()
  {
    return this.seriesAttrColor;
  }

  public void setBorderLineStyle(int paramInt)
  {
    getSeriesAttrBorder().setBorderStyle(paramInt);
  }

  public int getBorderLineStyle()
  {
    return getSeriesAttrBorder().getBorderStyle();
  }

  public void setBorderLineColor(Color paramColor)
  {
    getSeriesAttrBorder().setBorderColor(paramColor);
  }

  public Color getBorderLineColor()
  {
    return getSeriesAttrBorder().getBorderColor();
  }

  public void setSeriesAttrBorder(SeriesAttrBorder paramSeriesAttrBorder)
  {
    this.seriesAttrBorder = paramSeriesAttrBorder;
  }

  public SeriesAttrBorder getSeriesAttrBorder()
  {
    return this.seriesAttrBorder;
  }

  public void setDefaultAlpha(float paramFloat)
  {
    getSeriesAttrAlpha().setAlpha(paramFloat);
  }

  public float getDefaultAlpha()
  {
    return getSeriesAttrAlpha().getAlpha();
  }

  public void setSeriesAttrAlpha(SeriesAttrAlpha paramSeriesAttrAlpha)
  {
    this.seriesAttrAlpha = paramSeriesAttrAlpha;
  }

  public SeriesAttrAlpha getSeriesAttrAlpha()
  {
    return this.seriesAttrAlpha;
  }

  public void paint(Graphics paramGraphics, Shape paramShape)
  {
    if (paramShape == null)
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Composite localComposite = localGraphics2D.getComposite();
    Paint localPaint = localGraphics2D.getPaint();
    localGraphics2D.setComposite(AlphaComposite.getInstance(3, getDefaultAlpha()));
    if (getSeriesColor() != null)
    {
      localGraphics2D.setPaint(getSeriesColor());
      localGraphics2D.fill(paramShape);
    }
    if ((getBorderLineStyle() != 0) && (getBorderLineColor() != null))
    {
      localGraphics2D.setPaint(getBorderLineColor());
      GraphHelper.draw(localGraphics2D, paramShape, getBorderLineStyle());
    }
    localGraphics2D.setComposite(localComposite);
    localGraphics2D.setPaint(localPaint);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("borderStyle")) != null)
          setBorderLineStyle(Integer.parseInt(str2));
        if ((str2 = paramXMLableReader.getAttr("borderColor")) != null)
          setBorderLineColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("seriesColor")) != null)
          setSeriesColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("defaultAlpha")) != null)
          setDefaultAlpha(Float.parseFloat(str2));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ColorInfo");
    paramXMLPrintWriter.startTAG("Attr").attr("borderStyle", getBorderLineStyle());
    if (getBorderLineColor() != null)
      paramXMLPrintWriter.attr("borderColor", getBorderLineColor().getRGB());
    if (getSeriesColor() != null)
      paramXMLPrintWriter.attr("seriesColor", getSeriesColor().getRGB());
    paramXMLPrintWriter.attr("defaultAlpha", getDefaultAlpha());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ColorInfo localColorInfo = (ColorInfo)super.clone();
    return localColorInfo;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ColorInfo))
      return false;
    ColorInfo localColorInfo = (ColorInfo)paramObject;
    if (localColorInfo.getBorderLineStyle() != getBorderLineStyle())
      return false;
    if (!(Equals.equals(localColorInfo.getBorderLineColor(), getBorderLineColor())))
      return false;
    if (!(Equals.equals(localColorInfo.getSeriesColor(), getSeriesColor())))
      return false;
    return (localColorInfo.getDefaultAlpha() == getDefaultAlpha());
  }

  public void dealCondition(SeriesCollection paramSeriesCollection, int paramInt)
  {
    SeriesAttrColor localSeriesAttrColor = (SeriesAttrColor)paramSeriesCollection.getSeriesCondition(new SeriesAttrColor(), paramInt);
    setSeriesColor(localSeriesAttrColor.getSeriesColor());
    SeriesAttrBorder localSeriesAttrBorder = (SeriesAttrBorder)paramSeriesCollection.getSeriesCondition(new SeriesAttrBorder(), paramInt);
    setBorderLineColor(localSeriesAttrBorder.getBorderColor());
    setBorderLineStyle(localSeriesAttrBorder.getBorderStyle());
    SeriesAttrAlpha localSeriesAttrAlpha = (SeriesAttrAlpha)paramSeriesCollection.getSeriesCondition(new SeriesAttrAlpha(), paramInt);
    setDefaultAlpha(localSeriesAttrAlpha.getAlpha());
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    if (this.seriesAttrAlpha != null)
      localJSONObject.put("seriesAttrAlpha", this.seriesAttrAlpha.toJSONObject());
    if (this.seriesAttrBorder != null)
      localJSONObject.put("seriesAttrBorder", this.seriesAttrBorder.toJSONObject());
    if (this.seriesAttrColor != null)
      localJSONObject.put("seriesAttrColor", this.seriesAttrColor.toJSONObject());
    return localJSONObject;
  }
}